home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_nub_robotboss.cog < prev    next >
Text File  |  1999-11-15  |  9KB  |  385 lines

  1. # Jones 3D Cog Script
  2. #
  3. # nub_RobotBoss.cog
  4. #
  5. # AI enhancements for Nub's Tomb Robot Boss
  6. #
  7. # [MDR]
  8. #
  9. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  10. #
  11. # ===================================================================
  12.  
  13. # ===================================================================
  14. symbols
  15.  
  16. message        startup
  17. message        aievent
  18. message        arrivedwpnt
  19. message        timer
  20. message        pulse
  21. message        entered
  22. message        exited
  23. message        user0
  24. message        user1
  25.  
  26. # ************************** SUBROUTINES ***********************
  27. flex        BeginWpntPatrol            local
  28.  
  29. # ************************** TEMPLATES *************************
  30. template    tpl_Boss=robot_boss        local
  31.  
  32. # ************************** MISC LINKED GEOM ******************
  33. int            n_NumWpnts=14            local
  34. thing        t_Wpnt00
  35. thing        t_Wpnt01
  36. thing        t_Wpnt02
  37. thing        t_Wpnt03
  38. thing        t_Wpnt04
  39. thing        t_Wpnt05
  40. thing        t_Wpnt06
  41. thing        t_Wpnt07
  42. thing        t_Wpnt08
  43. thing        t_Wpnt09
  44. thing        t_Wpnt10
  45. thing        t_Wpnt11
  46. thing        t_Wpnt12
  47. thing        t_Wpnt13
  48.  
  49. thing        t_LookCenter
  50. thing        hint52                    #added 10/17/99 GGJ
  51.  
  52. sector        sec_upperTnl
  53.  
  54. # ************************** MISC LOCAL VARS *******************
  55. thing        t_player                local
  56. thing        t_boss                    local
  57.  
  58. int            TIMERID_STUN=1            local
  59.  
  60. int            n_eventType                local
  61. int            n_param                    local
  62. int            n_CrntAIMode            local
  63.  
  64. int            n_crntWpnt                local
  65. int            n_nextWpnt                local
  66. int            n_marchToWpnt            local
  67.  
  68. int            b_IndyInTunnel            local
  69.  
  70. int            n_damage                local
  71. int            n_idx                    local
  72. flex        f_val                    local
  73. flex        f_distToPlayer            local
  74. flex        f_distClearPath            local
  75. flex        DIST_MINCHECK            local
  76. flex        DIST_MINPATH            local
  77. flex        SPEED_MAX                local
  78.  
  79. vector        vec_pos                    local
  80.  
  81. end
  82.  
  83.  
  84. # ===================================================================
  85. code
  86.  
  87. # ...................................................................
  88. startup:
  89.  
  90. #        HACK!
  91. #    t_player = GetLocalPlayerThing();
  92. #    ChangeInv(t_Player, 78, 1.0);
  93. #    SetInvAvailable(t_Player, 78, 1);
  94. #    JonesInvItemChanged(78);
  95.  
  96.     return;
  97.  
  98.  
  99. # ...................................................................
  100. aievent:
  101.  
  102.     if ( GetSenderRef() != t_boss ) return;
  103.  
  104.     n_eventType        = GetParam(0);
  105.     n_CrntAIMode    = GetParam(1);
  106.     n_param            = GetParam(2);                            # Value depends on n_eventType
  107.  
  108.     if ( n_eventType == 0x100 )                                #---- EVENT_MODECHANGED
  109.     {                                                            # n_param == old AI mode
  110.         if ( !BITTEST(n_param, 0x4) && BITTEST(n_crntAIMode, 0x4) )
  111.         {                                                        # Switched to MODE_SEARCHING?
  112. #            DEBUGPRINT("AIEVENT:: Switched to SEARCH mode");
  113.             call BeginWpntPatrol;
  114.         }
  115.     }
  116.  
  117.     if ( BITTEST(n_eventType, 0x600) )                        #---- SITHAI_EVENTHIT(WALL|CLIFF) ----
  118.     {
  119.         if ( BITTEST(AIGetMode(t_boss), 0x4000000) )            # Traversing waypoints?
  120.         {
  121.             ReturnEx(1);
  122.         }
  123.     }
  124.  
  125.     if ( n_eventType == 0x4 )                                #---- EVENT_TOUCHED ----
  126.     {                                                            # n_param == touched THING index
  127.         if ( n_param == t_player )
  128.         {
  129.             StopThing(t_player);
  130.         }
  131.  
  132.         ReturnEx(1);
  133.     }
  134.  
  135.     return;
  136.  
  137.  
  138. # ...................................................................
  139. pulse:
  140.  
  141.     if ( t_boss == -1 )
  142.     {
  143.         SetPulse(0);
  144.         return;
  145.     }
  146.  
  147.     AISetMoveSpeed(t_boss, SPEED_MAX);
  148.  
  149.     if ( b_IndyInTunnel == 1 )
  150.         return;
  151.  
  152.     if ( BITTEST(GetActorFlags(t_boss), 0x40000) )                    # AF_IMMOBILE?
  153.         return;
  154.  
  155.     if ( IsModePlaying(t_boss, 67) )                                # Firing ranged weapon?
  156.         return;
  157.  
  158.     f_distToPlayer = VectorLen( VectorSub(GetThingPos(t_boss), GetThingPos(t_player)) );
  159. #    DEBUGFLEX(f_distToPlayer, "Dist to player =");
  160.     if ( f_distToPlayer > DIST_MINCHECK )
  161.     {
  162.         f_distClearPath = CheckPathToPoint(t_boss, GetThingPos(t_player), 0, 0);
  163. #        DEBUGFLEX(f_distClearPath, "Clear dist to player =");
  164.  
  165.         if ( !BITTEST(AIGetMode(t_boss), 0x4000000) )                # !Already in MODE_TRAVERSEWPNTS?
  166.         {
  167.             if ( (f_distClearPath < DIST_MINPATH) || !IsThingMoving(t_boss) )
  168.             {
  169.                 AISetSubMode(t_boss, 0x8000);                        # Set SUBMODE_CONTINUOUSWPNTMOTION
  170.                 AIWpntHuntTarget(t_boss, SPEED_MAX, 0);
  171. #                DEBUGPRINT("PULSE:: Started HUNT");
  172.                 return;
  173.             }
  174.         }
  175.     }
  176.     else
  177.     {
  178.         AIClearSubMode(t_boss, 0x8000);                                # Clear SUBMODE_CONTINUOUSWPNTMOTION
  179.         AIClearTraverseWpnts(t_boss);                                # Clear wpnt status
  180.     }
  181. #    DEBUGPRINT("---------");
  182.  
  183.     return;
  184.  
  185.  
  186. # ...................................................................
  187. arrivedwpnt:
  188.  
  189.     n_crntWpnt = GetParam(0);
  190.     n_nextWpnt = GetParam(1);
  191.  
  192. #    DEBUGPRINT("---------");
  193. #    DEBUGFLEX(n_crntWpnt, "Arrived Wpnt");
  194.  
  195.     if ( n_crntWpnt == n_marchToWpnt )
  196.     {
  197.         n_marchToWpnt = -1;
  198.  
  199.         AIClearSubMode(t_boss, 0x8000);                            # Clear SUBMODE_CONTINUOUSWPNTMOTION
  200.         AIStopFlee(t_boss);
  201.         AISetLookThing(t_boss, t_LookCenter);
  202.         AISetFireTarget(t_boss, t_player);
  203.  
  204. #        DEBUGPRINT("---------");
  205.         return;
  206.     }
  207.  
  208.     f_distToPlayer = VectorLen( VectorSub(GetThingPos(t_boss), GetThingPos(t_player)) );
  209. #    DEBUGFLEX(f_distToPlayer, "Dist to player =");
  210.  
  211.     if ( f_distToPlayer <= DIST_MINCHECK )
  212.     {
  213.         AIClearSubMode(t_boss, 0x8000);                            # Clear SUBMODE_CONTINUOUSWPNTMOTION
  214.         AIClearTraverseWpnts(t_boss);                            # Clear wpnt status
  215.  
  216. #        DEBUGPRINT("---------");
  217.         return;
  218.     }
  219.  
  220.     f_distClearPath = CheckPathToPoint(t_boss, GetThingPos(t_player), 0, 0);
  221. #    DEBUGFLEX(f_distClearPath, "Clear dist to player =");
  222.  
  223.     if ( f_distClearPath >= DIST_MINPATH )
  224.     {
  225.         AIClearSubMode(t_boss, 0x8000);                            # Clear SUBMODE_CONTINUOUSWPNTMOTION
  226.         AIClearTraverseWpnts(t_boss);                            # Clear wpnt status
  227. #        DEBUGPRINT("---------");
  228.     }
  229.  
  230.     return;
  231.  
  232.  
  233. # ...................................................................
  234. timer:
  235.  
  236.     if ( GetSenderID() == TIMERID_STUN )
  237.     {
  238.         AIClearCutsceneMode(t_boss);                        # Clear cutscene mode
  239.         ClearActorFlags(t_boss, 0x40000);                    # Clear AF_IMMOBILE while stunned
  240.         call BeginWpntPatrol;
  241.     }
  242.  
  243.     return;
  244.  
  245.  
  246. # ...................................................................
  247. entered:
  248.  
  249.     if ( GetSenderRef() == sec_upperTnl )
  250.     {
  251.         b_IndyInTunnel = 1;
  252.         AISetSubMode(t_boss, 0x8000);                            # Set SUBMODE_CONTINUOUSWPNTMOTION
  253.  
  254.         n_nextWpnt = AIFindNearestWpnt(t_boss);
  255.         if ( n_nextWpnt>=0 && n_nextWpnt<=2 )
  256.         {
  257.             n_marchToWpnt = 1;
  258.         }
  259.         else
  260.         {
  261.             n_marchToWpnt = 4;
  262.         }
  263.  
  264.         AIFleeToWpnt(t_boss, n_marchToWpnt);
  265.  
  266.         AIEnableInstinct(t_boss, "basicfollow", 0);
  267.         AIEnableInstinct(t_boss, "primaryfire", 0);
  268.     }
  269.  
  270.     return;
  271.  
  272.  
  273. # ...................................................................
  274. exited:
  275.  
  276.     if ( GetSenderRef() == sec_upperTnl )
  277.     {
  278.         b_IndyInTunnel = 0;
  279.         AIClearSubMode(t_boss, 0x8000);                            # Clear SUBMODE_CONTINUOUSWPNTMOTION
  280.         AIStopFlee(t_boss);
  281.  
  282.         AIEnableInstinct(t_boss, "basicfollow", 1);
  283.         AIEnableInstinct(t_boss, "primaryfire", 1);
  284.     }
  285.  
  286.     return;
  287.  
  288.  
  289. # ...................................................................
  290. # Create a Boss Robot at location-THING == GetParam(0)        [must be a valid THING]
  291. user0:
  292.  
  293.     t_boss = CreateThing(tpl_Boss, GetParam(0));
  294. //    AttachThingToThing(hint52, t_boss);                #added 10/17/99 GGJ
  295.     vec_pos = VectorAdd(GetThingPos(t_boss), '0 0 0.3');
  296.     SetThingPosEx(hint52, vec_pos, FindNewSectorFromThing(t_boss, vec_pos));
  297.     AttachThingToThing(hint52, t_boss);                #added 10/17/99 GGJ
  298.  
  299.     CaptureThing(t_boss);
  300.     AISetInstinctWpntMode(t_boss);
  301.     AISetSubMode(t_boss, 0x8000);                            # Set SUBMODE_CONTINUOUSWPNTMOTION
  302.  
  303.     # Initialize waypoint system for this section
  304.     for ( n_idx = 0; n_idx < n_NumWpnts; n_idx = n_idx + 1 )
  305.     {
  306.         AISetWpnt(t_Wpnt00[n_idx], n_idx);
  307.     }
  308.  
  309.     AIConnectWpnts(0, 7);
  310.     AIConnectWpnts(7, 1);
  311.     AIConnectWpnts(1, 6);
  312.     AIConnectWpnts(6, 2);
  313.     AIConnectWpnts(2, 13);
  314.     AIConnectWpnts(13, 12);
  315.     AIConnectWpnts(12, 3);
  316.     AIConnectWpnts(3, 11);
  317.     AIConnectWpnts(11, 4);
  318.     AIConnectWpnts(4, 10);
  319.     AIConnectWpnts(10, 5);
  320.     AIConnectWpnts(5, 9);
  321.     AIConnectWpnts(9, 8);
  322.     AIConnectWpnts(8, 0);
  323.  
  324.     t_player        = GetLocalPlayerThing();
  325.     n_marchToWpnt    = -1;
  326.     b_IndyInTunnel    = 0;
  327.  
  328.     DIST_MINCHECK    = 0.4;
  329.     DIST_MINPATH    = 0.3;
  330.     SPEED_MAX        = 1.5;
  331.  
  332.     SetPulse(3.0);
  333.  
  334.     ReturnEx(t_boss);                                        # Set Boss THING index for return to caller
  335.  
  336.     return;
  337.  
  338.  
  339. # ...................................................................
  340. # Inflict damage on Boss and temporarily 'stun' him
  341. user1:
  342.  
  343.     n_damage = GetParam(0);
  344. #    DEBUGFLEX(n_damage, "Robot Boss:: Damage to boss =");
  345.  
  346.     StopThing(t_boss);
  347.     AISetCutsceneMode(t_boss);                                # Set cutscene mode while stunned
  348.     SetActorFlags(t_boss, 0x40000);                            # Set SITH_AF_IMMOBILE while stunned
  349.  
  350.     DamageThing(t_boss, n_damage, 0x100000, t_boss);        # Inflict SITH_DAMAGE_LIGHTNING on Boss
  351.     if ( GetThingHealth(t_boss) > 0 )
  352.     {
  353.         PlayMode(t_boss, 75, 0);                            # Play SITH_PUPPETADDIN_HIT manually
  354.         SetTimerEx(4.0, TIMERID_STUN, 0, 0);                # Timer to clear hurt mode
  355.     }
  356.     else
  357.     {
  358.         t_boss = -1;
  359.     }
  360.  
  361.     return;
  362.  
  363.  
  364. # ===================================================================
  365. #    Subroutines
  366. # ===================================================================
  367.  
  368. # ...................................................................
  369. BeginWpntPatrol:
  370.  
  371.     if ( BITTEST(AIGetMode(t_boss), 0x4000000) )            # Already in MODE_TRAVERSEWPNTS?
  372.         return;
  373.  
  374.     n_nextWpnt = AIFindNearestWpnt(t_boss);
  375.     if ( n_nextWpnt > -1 )
  376.     {
  377.         AITraverseWpnts(t_boss, n_nextWpnt, SPEED_MAX, 0, 0);
  378.     }
  379.  
  380.     return;
  381.  
  382.  
  383. end
  384.  
  385.